package com.study.common;

public class RestfulResult<T> {

    private String code = "success";

    private T data = null;

    private String message;

    private boolean success = true;

    public RestfulResult(boolean success, String code, String message, T data) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.success = success;
    }

    public RestfulResult(T data) {
        this.data = data;
    }

    public RestfulResult() {
    }

    public static <T> RestfulResult<T> success(T data) {
        return new RestfulResult(data);
    }

    public static <T> RestfulResult<T> success() {
        return new RestfulResult();
    }

    public static <T> RestfulResult<T> fail(String code, String message, T data) {
        return new RestfulResult(false, code, message, data);
    }

    public static <T> RestfulResult<T> fail(String code, String message) {
        return new RestfulResult(false, code, message, null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}

